<?php

include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Controllers.php';
include dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ValidatorController.php';
include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . 'MyModules.php';
include dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'lang' . DIRECTORY_SEPARATOR . 'lang_vi.php';

class MyControllers extends Controllers {

    function __construct($aryConfigDB, $aryConfigs) {
        parent::__construct();
        if ($this->getParam('ajax') != 1) {
//            $this->setHeader();
        }
        $this->_objConfig = $aryConfigs;
        $this->assign('root_page', $this->_rootPage);
        $this->_objModule = new MyModules($aryConfigDB);
    }

    function __destruct() {
        if ($this->getParam('ajax') != 1) {
//            $this->setFooter();
        }
    }

    public function def() {

//        $this->buildNews();
        $this->getTopProduct();
//        $this->getSessionCustomer();
//
//        $this->listSupportOnline();
//
//        $this->getSlider();
//
//        $cookieShopCat = $this->getCookieData('globe_shopcat');
//
//        if (strlen($cookieShopCat) == 0) {
//            $this->setCookieShopCat();
//        }
//        $this->getProductOrder();
//        $this->buildMenu();
//        $this->buildRightItem();
        $limit = $this->getConfig('product_right_item_per_page');
//        $intOk = $this->_objModule->getProductByType(1, $aryProductNew, $limit);
//        $this->assign('aryProductNew', $aryProductNew);
        $this->assign('title', $this->getConfig('title'));
        $this->assign('description', $this->getConfig('description'));
        $this->assign('keywords', $this->getConfig('keywords'));
        $this->setViewTemplate('home', 'vmc_home');
    }

    public function getTopProduct() {
        $aryTopProduct = array();
        $limit = $this->getConfig('limit_top_product');
        $this->_objModule->getTopProduct($aryTopProduct, $limit);
        $this->assign('aryTopProduct', $aryTopProduct);
    }

    public function buildMenu() {
        $intOk = $this->_objModule->getProductCategory($aryProductCategory);
        $aryRootCategory = array();
        $arySubCategory = array();
        $k = 0;
        foreach ($aryProductCategory as $key => $value) {
            if ($value['category_parent'] == 0) {
                $aryRootCategory[$key]['category_id'] = $value['category_id'];
                $aryRootCategory[$key]['category_name'] = $value['category_name'];
                $aryRootCategory[$key]['category_name_filter'] = $value['category_name_filter'];
                $aryRootCategory[$key]['category_description_felter'] = $value['category_description_felter'];
                $aryRootCategory[$key]['category_main_image'] = $value['category_main_image'];
                $aryRootCategory[$key]['category_small_image'] = $value['category_small_image'];
                $aryRootCategory[$key]['category_total_child'] = $value['category_total_child'];
                $arySubCategory[$value['category_id']]['category_id'] = $value['category_id'];
            }
            if ($value['category_parent'] && $value['category_level'] == 1) {
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_id'] = $value['category_id'];
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_name'] = $value['category_name'];
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_name_filter'] = $value['category_name_filter'];
                $arySubCategory[$value['category_parent']]['sub_category'][$value['category_id']]['category_total_child'] = $value['category_total_child'];
            }
        }
        $this->assign('aryRootCategory', $aryRootCategory);
        $this->assign('arySubcategory', $arySubCategory);
    }

    public function buildRightItem($listCategory = null) {

        $aryProuductType = $this->getConfig('product_type');

        $aryProductByType = array();

        $limit = $this->getConfig('product_right_item_per_page');

        foreach ($aryProuductType as $key => $value) {

            $this->_objModule->getProductByType($key, $aryProductByType[$key], $limit, $listCategory);
        }

        $this->assign('aryProductByType', $aryProductByType);

        $this->assign('aryProductType', $aryProuductType);
    }

    public function sanpham() {

        $this->getSessionCustomer();

        $listType = $this->getCookieData('listType');

        $this->buildMenu();

        $this->listSupportOnline();

        $productId = $this->getParamOnUrlByKey(1);

        $this->getProductImage();

        $intOk = $this->_objModule->getProductById($productId, $aryProduct);

//        print_r($aryProduct);

        $categoryId = $aryProduct[0]['product_category_id'];

        $aryCategoryParent = $this->buildParentList($categoryId);

        $this->assign('categoryParent', $aryCategoryParent);

        $this->getTopProduct();

        $makerId = $aryProduct[0]['product_maker_id'];

        $categoryId = $aryProduct[0]['product_category_id'];

        $limit = $this->getConfig('product_right_item_per_page');

//        $intOk = $this->_objModule->getProductSamePrice($price, $limit, $aryProductSamePrice);
//        $intOk = $this->_objModule->getProductSameMaker($makerId, $categoryId, 8, $aryProductSameMaker);

        $intOk = $this->_objModule->getProductSameCategory($categoryId, $aryProductSameCategory);

//        $intOk = $this->_objModule->getProductByType(1, $aryProductNew, $limit, $categoryId);
//        $intOk = $this->_objModule->getProductByType(2, $aryProductKm, $limit, $categoryId);
//        $intOk = $this->_objModule->getProductByType(3, $aryProductSellers, $limit, $categoryId);
//        $this->assign('aryProductNew', $aryProductNew);
//        $this->assign('aryProductKm', $aryProductKm);
//        $this->assign('aryProductSellers', $aryProductSellers);
//        $intOk = $this->_objModule->getSpecsByCategory($categoryId, $arySpecs);
//        $intOk = $this->_objModule->getSpecsDetailByProductId($productId, $aryProductSpecs);
//        foreach ($aryProductSpecs as $key => $value) {
//
//            $aryProductSpecsId[] = $value['product_specs_specs_id'];
//            $arySpecsInputName[$value['product_specs_specs_id']] = $value['product_specs_specs_name'];
//        }
//        foreach ($arySpecs as $key => $value) {
//            if (in_array($value['specs_id'], $aryProductSpecsId)) {
//                $arySpecs[$key]['selected'] = 1;
//            }
//        }
//        foreach ($arySpecs as $key => $value) {
//            if ($value['specs_level'] == 0) {
//                $aryTreeSpecs[$value['specs_id']]['specs_id'] = $value['specs_id'];
//                $aryTreeSpecs[$value['specs_id']]['specs_name'] = $value['specs_name'];
//                $aryTreeSpecs[$value['specs_id']]['specs_total_child'] = $value['specs_total_child'];
//            }
//            if ($value['specs_level'] == 1) {
//                $aryTreeSpecs[$value['specs_parent']]['sub_category_info'][$value['specs_id']]['specs_id'] = $value['specs_id'];
//                $aryTreeSpecs[$value['specs_parent']]['sub_category_info'][$value['specs_id']]['specs_name'] = $value['specs_name'];
//            }
//            if ($value['specs_level'] == 2 && $value['selected'] == 1) {
//                $root = $this->_objModule->getSecsParentPath($value['specs_id']);
//                $aryTreeSpecs[$root[0]]['sub_category_info'][$value['specs_parent']]['sub_specs_name'][] = $value['specs_name'];
//            }
//            if ($value['specs_input_type'] == 3 || $value['specs_input_type'] == 5) {
//                $root = $this->_objModule->getSecsParentPath($value['specs_id']);
//                $aryTreeSpecs[$root[0]]['sub_category_info'][$value['specs_id']]['sub_specs_name'][] = $arySpecsInputName[$value['specs_id']];
//            }
//        }

        $cookieShopCat = $this->getCookieData('globe_shopcat');

//        $inOk = $this->_objModule->getProductIdInOrder($cookieShopCat, $aryProductOrder);

        $aryOrderProductId = array();
        if (isset($aryProductOrder[0])) {
            foreach ($aryProductOrder as $key => $value) {

                $aryOrderProductId[] = $value['product_order_product_id'];
            }
        }

        //haimv- change Description for SEO keyword

        $titleConf = $this->getConfig('title');
        $strTitle = $aryProduct[0]['product_title'];

        $strKeywords = str_replace("(", ",", $aryProduct[0]['product_title']);
        $strKeywords = str_replace(")", ",", $strKeywords);
        $strKeywords = str_replace(" ", ",", $strKeywords);
        $strDescription = $aryProduct[0]['product_title'] . '-' . $titleConf;
        $this->listSupportOnline();
        $this->assign('aryProductSameMaker', $aryProductSameMaker);
        $this->assign('aryProductSameCategory', $aryProductSameCategory);
        $this->assign('aryOrderProductId', $aryOrderProductId);
        $this->assign('title', $strTitle);
        $this->assign('description', $strDescription);
        $this->assign('keywords', $strKeywords);
        $this->assign('listType', $listType);
        $this->assign('aryProductSpecs', $aryTreeSpecs);
        $this->assign('aryProduct', $aryProduct[0]);
        $aryCustomer = $this->getSession('customer');
        $this->assign('aryCustomer', $aryCustomer);
        $this->setViewTemplate('home', 'product_detail');
    }

    public function listSupportOnline() {
        $this->assign('arySupport', $this->getConfig('support_online'));
    }

    public function buildParentList($categoryId) {

        $aryCatParentId = $this->_objModule->getCategoryParentPath($categoryId);

        array_push($aryCatParentId, $categoryId);

        $listCatParent = @implode(',', $aryCatParentId);

        $this->_objModule->getCategoryByListId($listCatParent, $aryCategoryParent);

        return $aryCategoryParent;
    }

    public function getProductOrder() {

        $this->getSessionCustomer();

        $cookieShopCat = $this->getCookieData('globe_shopcat');

        $inOk = $this->_objModule->getProductOrderByCookie($cookieShopCat, $aryProductOrder);

        $this->_objModule->getProductOrderDetail($cookieShopCat, $aryProductOrderDetail);

        $this->assign('aryProductOrderDetail', $aryProductOrderDetail[0]);

        $aryOrderProductId = array();

        $totalPrice = 0;
        $totalProduct = 0;
        $aryProduct = array();
        if (isset($aryProductOrder[0])) {
            foreach ($aryProductOrder as $key => $value) {

                $aryOrderProductId[] = $value['product_order_product_id'];

                $totalPrice = $totalPrice + $value['product_order_total_price'];

                $aryProduct[$key]['product_order_id'] = $value['product_order_id'];
                $aryProduct[$key]['product_order_product_id'] = $value['product_order_product_id'];
                $aryProduct[$key]['product_order_product_name'] = $value['product_order_product_name'];
                $aryProduct[$key]['product_order_product_filter_name'] = $this->filterUnicode($value['product_order_product_name']);
                $aryProduct[$key]['product_order_total_product'] = $value['product_order_total_product'];
                $aryProduct[$key]['product_order_product_price'] = $value['product_order_product_price'];
                $aryProduct[$key]['product_order_total_price'] = $value['product_order_total_price'];
                $aryProduct[$key]['product_order_active'] = $value['product_order_active'];
                $aryProduct[$key]['product_order_product_image'] = $value['product_order_product_image'];
                $aryProduct[$key]['product_order_category_id'] = $value['product_order_category_id'];
                $aryProduct[$key]['product_order_category_name'] = $value['product_order_category_name'];
                $aryProduct[$key]['product_order_category_filter'] = $value['product_order_category_filter'];
                $totalProduct++;
            }
        }


        $this->assign('aryOrderProductId', $aryOrderProductId);

        $this->assign('aryProductOrder', $aryProduct);

        $this->assign('totalPrice', $totalPrice);

        $this->assign('totalProduct', $totalProduct);

        return $totalProduct;
    }

    public function danhmuc() {

        $listType = $this->getCookieData('listType');

        if ($listType == '') {
            $listType = 1;
        }
        $this->listSupportOnline();

        $this->buildMenu();

        $this->getTopProduct();

        $url = $_SERVER['REQUEST_URI'];

        $this->assign('url', $url);

        $url = preg_replace('/\?page=([0-9]+)/', '', $url);

        $url = preg_replace('/\.html/', '', $url);

        $categoryId = $this->getParamOnUrlByKey(1);

        $categoryHtml = $this->getParamOnUrlByKey(2);

        $categoryHtml = preg_replace('/\?page=([0-9]+)/', '', $categoryHtml);

        if (preg_match('/.html/', $categoryHtml)) {

            $categoryNameFilter = str_replace('.html', '', $categoryHtml);
        } else {

            $categoryNameFilter = $categoryHtml;
        }

        $makerName = $this->getParamOnUrlByKey(3);

        if ($makerName == '') {

            $makerName = 'all';
        }

        $filterPrice = $this->getParamOnUrlByKey(4);

        if ($filterPrice == '') {

            $filterPrice = 'price:all';
        }

        $aryFilterPrice = @explode(':', $filterPrice);

        $this->_objModule->getSubCatByCatId($categoryId, $aryCategory);

        foreach ($aryCategory as $key => $value) {
            $arySubCategoryId[] = $value['category_id'];
        }

        $aryCategoryParent = $this->buildParentList($categoryId);

        $this->assign('categoryParent', $aryCategoryParent);

        $strTitle = '';

        if (isset($aryCategoryParent[0])) {

            foreach ($aryCategoryParent as $key => $value) {
                $strTitle = $value['category_name'];
                $keywords = $value['category_keyword'];
            }
        }

        $this->assign('keywords', $keywords);

        $this->assign('title', $strTitle);

        $aryCategoryId = $this->_objModule->getCategoryChildPath($categoryId);

        if (count($aryCategoryId) > 0) {

            $hasChildCategory = 1;

            $listCategoryId = @implode(",", $aryCategoryId);

            $listSubCategoryIdForMaker = @implode(",", $arySubCategoryId);
        } else {

            $hasChildCategory = 0;

            $listCategoryId = $categoryId;

            $listSubCategoryIdForMaker = $categoryId;
        }
        if ($listSubCategoryIdForMaker != '') {
            $this->_objModule->getListProductMakerId($listSubCategoryIdForMaker, $aryProductMakerId);
        }

        foreach ($aryProductMakerId as $key => $value) {
            if ($value['product_maker_id'] != 0) {
                $aryMakerId[$value['product_maker_id']] = $value['product_maker_id'];
            }
        }

        if (isset($aryMakerId[0])) {
            $listMakerForSearch = @implode(",", $aryMakerId);
        }

        if ($listMakerForSearch != '') {
            $this->_objModule->getProductMakerByListId($listMakerForSearch, $aryMakerForSearch);
        }

        $this->assign('aryMakerForSearch', $aryMakerForSearch);

        $cookieOrder = $this->getCookieData('order');

        $this->assign('cookieOrder', $cookieOrder);

        $aryConditions = array();

        $aryConditions['list_category'] = $listCategoryId;

        $aryConditions['current_page'] = $this->getParam('page');

        if ($listType == 2) {
            $aryConditions['record_per_page'] = $this->getConfig('product_per_page_r');
        } else {
            $aryConditions['record_per_page'] = $this->getConfig('product_per_page');
        }

        $aryConditions['product_maker_name'] = $makerName;

        $aryConditions['has_child_category'] = $hasChildCategory;

        if ($cookieOrder == '') {
            $aryConditions['field'] = 'product_price_vnd';
            $aryConditions['order'] = 'DESC';
        }
        switch ($cookieOrder) {
            case "price_up":
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'ASC';
                break;
            case "price_down":
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'DESC';
                break;
            case "name_up":
                $aryConditions['field'] = 'product_title';
                $aryConditions['order'] = 'ASC';
                break;
            case "name_down":
                $aryConditions['field'] = 'product_title';
                $aryConditions['order'] = 'DESC';
                break;
        }

        if ($aryFilterPrice[1] != 'all') {
            $aryConditions['product_price_from'] = $aryFilterPrice[1];
            $aryConditions['product_from_to'] = $aryFilterPrice[2];
        }

        //get product id by specs id
        $strSpecs = $this->getParamOnUrlByKey(5);

        if ($strSpecs == '') {

            $strSpecs = 'specs';
        }

        $arySpescId = explode(':', $strSpecs);

        if (isset($arySpescId[1])) {

            unset($arySpescId[0]);

            $specsId = @implode(',', $arySpescId);

            $countSpecs = count($arySpescId);
            if ($specsId != '') {
                $this->_objModule->getProductListIdBySpecsId($specsId, $countSpecs, $aryProductListId);
            }
            foreach ($aryProductListId as $key => $value) {

                $aryproductid[] = $value['product_specs_product_id'];
            }

            $aryproductid = array_unique($aryproductid);
            if (isset($aryproductid[0])) {
                $listProductid = @implode(',', $aryproductid);
            }

            $aryConditions['list_product_id'] = $listProductid;

            $this->assign('arySpecsId', $arySpescId);
        }
        //end
        $this->_objModule->getProduct($aryConditions, $aryProduct, $aryProductConditions);

        $link = $url . '?page=';

        $strPaging = $this->pagination($link, $aryProduct['paging']);

        $this->buildRightItem($listCategoryId);

        if ($hasChildCategory == 1) {

//            $this->buildRightItem($listCategoryId);
        } else {

            $aryMakerId = array();

            $aryPrice = array();

            $aryProductId = array();

            if (isset($aryProductConditions[0])) {

                foreach ($aryProductConditions as $key => $value) {

                    $aryProductId[] = $value['product_id'];

                    $aryMakerId[$value['product_maker_id']] = $value['product_maker_id'];


                    if (0 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 50000) {
                        $aryPrice[0]['url'] = 'price:0:50000';
                        $aryPrice[0]['price_name'] = 'Từ 0 -> 50.000';
                        $aryPrice[0]['count']++;
                    }
                    if (50000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 100000) {
                        $aryPrice[1]['url'] = 'price:50000:100000';
                        $aryPrice[1]['price_name'] = 'Từ 50.000 -> 100.000';
                        $aryPrice[2]['count']++;
                    }
                    if (100000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 200000) {
                        $aryPrice[2]['url'] = 'price:100000:200000';
                        $aryPrice[2]['price_name'] = 'Từ 100.000 -> 200.000';
                        $aryPrice[2]['count']++;
                    }
                    if (200000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 300000) {
                        $aryPrice[3]['url'] = 'price:200000:300000';
                        $aryPrice[3]['price_name'] = 'Từ 200.000 -> 300.000';
                        $aryPrice[3]['count']++;
                    }
                    if (300000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 500000) {
                        $aryPrice[4]['url'] = 'price:300000:500000';
                        $aryPrice[4]['price_name'] = 'Từ 300.000 -> 500.000';
                        $aryPrice[4]['count']++;
                    }
                    if (500000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 1000000) {
                        $aryPrice[5]['url'] = 'price:500000:1000000';
                        $aryPrice[5]['price_name'] = 'Từ 500.000 -> 1 triệu';
                        $aryPrice[5]['count']++;
                    }
                    if (1000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 1500000) {
                        $aryPrice[6]['url'] = 'price:1000000:1500000';
                        $aryPrice[6]['price_name'] = 'Từ 1 -> 1.5 triệu';
                        $aryPrice[6]['count']++;
                    }
                    if (1500000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 2000000) {
                        $aryPrice[7]['url'] = 'price:1500000:2000000';
                        $aryPrice[7]['price_name'] = 'Từ 1.5 -> 2 triệu';
                        $aryPrice[7]['count']++;
                    }
                    if (2000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 3000000) {
                        $aryPrice[8]['url'] = 'price:2000000:3000000';
                        $aryPrice[8]['price_name'] = 'Từ 2 -> 3 triệu';
                        $aryPrice[8]['count']++;
                    }
                    if (3000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 5000000) {
                        $aryPrice[9]['url'] = 'price:3000000:5000000';
                        $aryPrice[9]['price_name'] = 'Từ 3 -> 5 triệu';
                        $aryPrice[9]['count']++;
                    }
                    if (5000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 7000000) {
                        $aryPrice[10]['url'] = 'price:5000000:7000000';
                        $aryPrice[10]['price_name'] = 'Từ 5 -> 7 triệu';
                        $aryPrice[10]['count']++;
                    }
                    if (7000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 10000000) {
                        $aryPrice[11]['url'] = 'price:7000000:10000000';
                        $aryPrice[11]['price_name'] = 'Từ 7 -> 10 triệu';
                        $aryPrice[11]['count']++;
                    }
                    if (10000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 15000000) {
                        $aryPrice[12]['url'] = 'price:10000000:15000000';
                        $aryPrice[12]['price_name'] = 'Từ 10 -> 15 triệu';
                        $aryPrice[12]['count']++;
                    }
                    if (15000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 20000000) {
                        $aryPrice[13]['url'] = 'price:15000000:20000000';
                        $aryPrice[13]['price_name'] = 'Từ 15 -> 20 triệu';
                        $aryPrice[13]['count']++;
                    }
                    if (20000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 25000000) {
                        $aryPrice[14]['url'] = 'price:20000000:25000000';
                        $aryPrice[14]['price_name'] = 'Từ 20 -> 25 triệu';
                        $aryPrice[14]['count']++;
                    }
                    if (25000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 30000000) {
                        $aryPrice[15]['url'] = 'price:25000000:30000000';
                        $aryPrice[15]['price_name'] = 'Từ 25 -> 30 triệu';
                        $aryPrice[15]['count']++;
                    }
                    if (30000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 40000000) {
                        $aryPrice[16]['url'] = 'price:30000000:40000000';
                        $aryPrice[16]['price_name'] = 'Từ 30 -> 40 triệu';
                        $aryPrice[16]['count']++;
                    }
                    if (40000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 50000000) {
                        $aryPrice[17]['url'] = 'price:40000000:50000000';
                        $aryPrice[17]['price_name'] = 'Từ 40 -> 50 triệu';
                        $aryPrice[17]['count']++;
                    }
                    if (50000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 70000000) {
                        $aryPrice[18]['url'] = 'price:50000000:70000000';
                        $aryPrice[18]['price_name'] = 'Từ 50 -> 70 triệu';
                        $aryPrice[18]['count']++;
                    }
                    if (70000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 100000000) {
                        $aryPrice[19]['url'] = 'price:70000000:100000000';
                        $aryPrice[19]['price_name'] = 'Từ 70 triệu -> 100 triệu';
                        $aryPrice[19]['count']++;
                    }
                    if (100000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 120000000) {
                        $aryPrice[20]['url'] = 'price:100000000:120000000';
                        $aryPrice[20]['price_name'] = 'Từ 100 triệu -> 120 triệu';
                        $aryPrice[20]['count']++;
                    }
                    if (120000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 150000000) {
                        $aryPrice[21]['url'] = 'price:120000000:150000000';
                        $aryPrice[21]['price_name'] = 'Từ 120 triệu -> 150 triệu';
                        $aryPrice[21]['count']++;
                    }
                    if (150000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 170000000) {
                        $aryPrice[22]['url'] = 'price:150000000:170000000';
                        $aryPrice[22]['price_name'] = 'Từ 150 triệu -> 170 triệu';
                        $aryPrice[22]['count']++;
                    }
                    if (170000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 200000000) {
                        $aryPrice[23]['url'] = 'price:170000000:200000000';
                        $aryPrice[23]['price_name'] = 'Từ 170 triệu -> 200 triệu';
                        $aryPrice[23]['count']++;
                    }
                    if (200000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 220000000) {
                        $aryPrice[24]['url'] = 'price:200000000:220000000';
                        $aryPrice[24]['price_name'] = 'Từ 200 triệu -> 220 triệu';
                        $aryPrice[24]['count']++;
                    }
                    if (220000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 250000000) {
                        $aryPrice[25]['url'] = 'price:220000000:250000000';
                        $aryPrice[25]['price_name'] = 'Từ 220 triệu -> 250 triệu';
                        $aryPrice[25]['count']++;
                    }
                    if (250000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 270000000) {
                        $aryPrice[26]['url'] = 'price:250000000:270000000';
                        $aryPrice[26]['price_name'] = 'Từ 250 triệu -> 270 triệu';
                        $aryPrice[26]['count']++;
                    }
                    if (270000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 300000000) {
                        $aryPrice[27]['url'] = 'price:270000000:300000000';
                        $aryPrice[27]['price_name'] = 'Từ 270 triệu -> 300 triệu';
                        $aryPrice[27]['count']++;
                    }
                    if (300000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 320000000) {
                        $aryPrice[28]['url'] = 'price:300000000:320000000';
                        $aryPrice[28]['price_name'] = 'Từ 300 triệu -> 320 triệu';
                        $aryPrice[28]['count']++;
                    }
                    if (320000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 350000000) {
                        $aryPrice[29]['url'] = 'price:320000000:350000000';
                        $aryPrice[29]['price_name'] = 'Từ 320 triệu -> 350 triệu';
                        $aryPrice[29]['count']++;
                    }
                    if (350000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 370000000) {
                        $aryPrice[30]['url'] = 'price:350000000:370000000';
                        $aryPrice[30]['price_name'] = 'Từ 350 triệu -> 370 triệu';
                        $aryPrice[30]['count']++;
                    }
                    if (370000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 400000000) {
                        $aryPrice[31]['url'] = 'price:370000000:400000000';
                        $aryPrice[31]['price_name'] = 'Từ 370 triệu -> 400 triệu';
                        $aryPrice[31]['count']++;
                    }
                    if (400000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 420000000) {
                        $aryPrice[32]['url'] = 'price:400000000:420000000';
                        $aryPrice[32]['price_name'] = 'Từ 400 triệu -> 420 triệu';
                        $aryPrice[32]['count']++;
                    }
                    if (420000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 450000000) {
                        $aryPrice[33]['url'] = 'price:420000000:450000000';
                        $aryPrice[33]['price_name'] = 'Từ 420 triệu -> 450 triệu';
                        $aryPrice[33]['count']++;
                    }
                    if (450000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 470000000) {
                        $aryPrice[34]['url'] = 'price:450000000:470000000';
                        $aryPrice[34]['price_name'] = 'Từ 450 triệu -> 470 triệu';
                        $aryPrice[34]['count']++;
                    }
                    if (470000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 500000000) {
                        $aryPrice[35]['url'] = 'price:470000000:500000000';
                        $aryPrice[35]['price_name'] = 'Từ 470 triệu -> 500 triệu';
                        $aryPrice[35]['count']++;
                    }
                    if (500000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 520000000) {
                        $aryPrice[36]['url'] = 'price:500000000:520000000';
                        $aryPrice[36]['price_name'] = 'Từ 500 triệu -> 520 triệu';
                        $aryPrice[36]['count']++;
                    }
                    if (520000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 550000000) {
                        $aryPrice[37]['url'] = 'price:520000000:550000000';
                        $aryPrice[37]['price_name'] = 'Từ 520 triệu -> 550 triệu';
                        $aryPrice[37]['count']++;
                    }
                    if (550000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 570000000) {
                        $aryPrice[38]['url'] = 'price:550000000:570000000';
                        $aryPrice[38]['price_name'] = 'Từ 550 triệu -> 570 triệu';
                        $aryPrice[38]['count']++;
                    }
                    if (570000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 600000000) {
                        $aryPrice[39]['url'] = 'price:570000000:600000000';
                        $aryPrice[39]['price_name'] = 'Từ 570 triệu -> 600 triệu';
                        $aryPrice[39]['count']++;
                    }
                    if (600000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 620000000) {
                        $aryPrice[40]['url'] = 'price:600000000:620000000';
                        $aryPrice[40]['price_name'] = 'Từ 600 triệu -> 620 triệu';
                        $aryPrice[40]['count']++;
                    }
                    if (620000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 650000000) {
                        $aryPrice[41]['url'] = 'price:620000000:650000000';
                        $aryPrice[41]['price_name'] = 'Từ 620 triệu -> 650 triệu';
                        $aryPrice[41]['count']++;
                    }
                    if (650000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 670000000) {
                        $aryPrice[42]['url'] = 'price:650000000:670000000';
                        $aryPrice[42]['price_name'] = 'Từ 650 triệu -> 670 triệu';
                        $aryPrice[42]['count']++;
                    }
                    if (670000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 700000000) {
                        $aryPrice[43]['url'] = 'price:670000000:700000000';
                        $aryPrice[43]['price_name'] = 'Từ 670 triệu -> 700 triệu';
                        $aryPrice[43]['count']++;
                    }
                    if (700000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 720000000) {
                        $aryPrice[44]['url'] = 'price:700000000:720000000';
                        $aryPrice[44]['price_name'] = 'Từ 700 triệu -> 720 triệu';
                        $aryPrice[44]['count']++;
                    }
                    if (720000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 750000000) {
                        $aryPrice[45]['url'] = 'price:720000000:750000000';
                        $aryPrice[45]['price_name'] = 'Từ 720 triệu -> 750 triệu';
                        $aryPrice[45]['count']++;
                    }
                    if (750000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 770000000) {
                        $aryPrice[46]['url'] = 'price:750000000:770000000';
                        $aryPrice[46]['price_name'] = 'Từ 750 triệu -> 770 triệu';
                        $aryPrice[46]['count']++;
                    }
                    if (770000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 800000000) {
                        $aryPrice[47]['url'] = 'price:770000000:800000000';
                        $aryPrice[47]['price_name'] = 'Từ 770 triệu -> 800 triệu';
                        $aryPrice[47]['count']++;
                    }
                    if (800000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 820000000) {
                        $aryPrice[48]['url'] = 'price:800000000:820000000';
                        $aryPrice[48]['price_name'] = 'Từ 800 triệu -> 820 triệu';
                        $aryPrice[48]['count']++;
                    }
                    if (820000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 850000000) {
                        $aryPrice[49]['url'] = 'price:820000000:850000000';
                        $aryPrice[49]['price_name'] = 'Từ 820 triệu -> 850 triệu';
                        $aryPrice[49]['count']++;
                    }
                    if (850000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 870000000) {
                        $aryPrice[50]['url'] = 'price:850000000:870000000';
                        $aryPrice[50]['price_name'] = 'Từ 850 triệu -> 870 triệu';
                        $aryPrice[50]['count']++;
                    }
                    if (870000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 900000000) {
                        $aryPrice[51]['url'] = 'price:870000000:900000000';
                        $aryPrice[51]['price_name'] = 'Từ 870 triệu -> 900 triệu';
                        $aryPrice[51]['count']++;
                    }
                    if (900000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 920000000) {
                        $aryPrice[52]['url'] = 'price:900000000:920000000';
                        $aryPrice[52]['price_name'] = 'Từ 900 triệu -> 920 triệu';
                        $aryPrice[52]['count']++;
                    }
                    if (920000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 950000000) {
                        $aryPrice[53]['url'] = 'price:920000000:950000000';
                        $aryPrice[53]['price_name'] = 'Từ 920 triệu -> 950 triệu';
                        $aryPrice[53]['count']++;
                    }
                    if (950000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 970000000) {
                        $aryPrice[54]['url'] = 'price:950000000:970000000';
                        $aryPrice[54]['price_name'] = 'Từ 950 triệu -> 970 triệu';
                        $aryPrice[54]['count']++;
                    }
                    if (970000000 < $value['product_price_vnd'] && $value['product_price_vnd'] <= 1000000000) {
                        $aryPrice[55]['url'] = 'price:970000000:1000000000';
                        $aryPrice[55]['price_name'] = 'Từ 970 triệu -> 1 tỷ';
                        $aryPrice[55]['count']++;
                    }
                }
            }
            if (is_array($aryPrice)) {

                $aryPrice = $this->sortArray($aryPrice);
            }

            $this->assign('aryPrice', $aryPrice);
            if (isset($aryMakerId[0])) {
                $listProductMakerId = @implode(',', $aryMakerId);
            }

            if ($listProductMakerId != '') {
                $this->_objModule->getProductMakerByListId($listProductMakerId, $aryProductMaker);
            }
            $this->assign('aryProductMaker', $aryProductMaker);
            if (isset($aryProductId[0])) {
                $listProductId = @implode(',', $aryProductId);
            }

            if ($listProductId != '') {

                $this->_objModule->getProductSpecsByProductId($listProductId, $aryProductSpecs);
            }

            $this->_objModule->getProductSpecsForFilterSpecs($categoryId, $aryFilterSpecs);

            foreach ($aryFilterSpecs as $key => $value) {

                $aryProductSpecsId[] = $value['specs_id'];

                $aryMainSpecs[$value['specs_id']]['specs_id'] = $value['specs_id'];
                $aryMainSpecs[$value['specs_id']]['specs_parent'] = $value['specs_parent'];
                $aryMainSpecs[$value['specs_id']]['specs_level'] = $value['specs_level'];
                $aryMainSpecs[$value['specs_id']]['specs_name'] = $value['specs_name'];
                $aryMainSpecs[$value['specs_id']]['specs_is_show'] = $value['specs_is_show'];
            }

//            print_r($aryMainSpecs);
            if (isset($aryProductSpecs[0])) {
                foreach ($aryProductSpecs as $key => $value) {
                    if (in_array($value['product_specs_specs_id'], $aryProductSpecsId)) {
                        $aryMainSpecs[$value['product_specs_specs_id']]['count']++;
                    }
                }
            }

            if (isset($aryMainSpecs[0])) {
                foreach ($aryMainSpecs as $key => $value) {
                    if ($value['specs_level'] == 0 && $value['specs_is_show'] == 0) {
                        $arySpecs[$value['specs_id']]['specs_id'] = $value['specs_id'];
                        $arySpecs[$value['specs_id']]['specs_name'] = $value['specs_name'];
                    }
                    if ($value['specs_level'] == 1 && $aryMainSpecs[$value['specs_parent']]['specs_is_show'] == 0) {
                        $arySpecs[$value['specs_parent']]['sub_specs'][$value['specs_id']]['specs_id'] = $value['specs_id'];
                        $arySpecs[$value['specs_parent']]['sub_specs'][$value['specs_id']]['specs_name'] = $value['specs_name'];
                    }
                    if ($value['specs_level'] == 2 && (isset($value['count']) && $value['count'] != '')) {
                        $parentNode = $value['specs_parent'];
                        $root = $aryMainSpecs[$parentNode]['specs_parent'];
                        $rootIsShow = $aryMainSpecs[$root]['specs_is_show'];
                        if ($rootIsShow == 0) {
                            $arySpecs[$root]['sub_specs'][$value['specs_parent']]['sub_specs_3'][$value['specs_id']]['specs_id'] = $value['specs_id'];
                            $arySpecs[$root]['sub_specs'][$value['specs_parent']]['sub_specs_3'][$value['specs_id']]['specs_name'] = $value['specs_name'];
                            $arySpecs[$root]['sub_specs'][$value['specs_parent']]['sub_specs_3'][$value['specs_id']]['specs_count'] = $value['count'];
                        }
                    }
                }
            }


            $this->assign('arySpecs', $arySpecs);

            $linkRemoveMaker = str_replace($makerName, 'all', $url);

            $this->assign('linkRemoveMaker', $linkRemoveMaker);

            $linkRemovePrice = str_replace($filterPrice, 'price:all', $url);

            $this->assign('linkRemovePrice', $linkRemovePrice);
        }

        $this->assign('strSpecs', $strSpecs);

        $this->assign('filterPrice', $filterPrice);

        $this->assign('makerName', $makerName);

        $this->assign('categoryId', $categoryId);

        $this->assign('categoryNameFilter', $categoryNameFilter);

        $this->assign('aryProduct', $aryProduct['data']);

        $this->assign('aryCategory', $aryCategory);

        $this->assign('hasChildCategory', $hasChildCategory);

        $this->assign('strPaging', $strPaging);

        $this->assign('priceFrom', $aryConditions['product_price_from']);

        $this->assign('priceTo', $aryConditions['product_from_to']);

        $aryCustomer = $this->getSession('customer');

        $this->assign(listType, $listType);

        $this->assign('aryCustomer', $aryCustomer);

        $this->setViewTemplate('home', 'product_list_product');
    }

    public function sortArray($inputArray) {
        $arySort = array_keys($inputArray);
        asort($arySort, SORT_NUMERIC);
        foreach ($arySort as $key => $value) {
            $aryAfterSort[] = $inputArray[$value];
        }
        return $aryAfterSort;
    }

    public function giohang() {

        $this->getProductOrder();

//        $this->buildMenu();

        $this->listSupportOnline();

        $cookieShopCat = $this->getCookieData('globe_shopcat');

        $aryMethodDelivery = $this->getConfig('method_delivery');

        $aryMethodPayment = $this->getConfig('method_payment');

        $this->assign('aryMethodDelivery', $aryMethodDelivery);

        $this->assign('aryMethodPayment', $aryMethodPayment);

        $this->assign('title', 'Chi tiết giỏ hàng.');

        $this->setViewTemplate('home', 'product_order');
    }

    public function saveProductToShopCat() {

        $cookieShopCat = $this->getCookieData('globe_shopcat');

        $productId = $this->getPostParam('productId');

        $categoryId = $this->getPostParam('categoryId');


        $this->_objModule->checkExistOrder($productId, $cookieShopCat, $aryResultData);

        $existed = false;

        if (isset($aryResultData[0])) {

            $existed = true;

            $intOk = -2;
        }

        if ($existed == false) {

            $intOk = $this->_objModule->getProductPriceById($productId, $aryData);

            $intOk = $this->_objModule->getCategoryByListId($categoryId, $aryCategory);

            if ($aryData[0]['product_price_active_km'] == 1) {

                $productPrice = $aryData[0]['product_price_vnd_km'];
            } else {

                $productPrice = $aryData[0]['product_price_vnd'];
            }
            $aryOrderInsert = array();
            $aryOrderInsert['product_order_cookie_id'] = $cookieShopCat;
            $aryOrderInsert['product_order_product_id'] = $productId;
            $aryOrderInsert['product_order_product_name'] = $aryData[0]['product_title'];
            $aryOrderInsert['product_order_product_image'] = $aryData[0]['product_main_image'];
            $aryOrderInsert['product_order_total_product'] = 1;
            $aryOrderInsert['product_order_category_id'] = $aryCategory[0]['category_id'];
            $aryOrderInsert['product_order_category_name'] = $aryCategory[0]['category_name'];
            $aryOrderInsert['product_order_category_filter'] = $aryCategory[0]['category_name_filter'];
            $aryOrderInsert['product_order_total_price'] = $productPrice;
            $aryOrderInsert['product_order_product_price'] = $productPrice;
            $aryOrderInsert['product_order_create_date'] = date('Y-m-d H:i:s');

            $intOk = $this->_objModule->insertProductOrder($aryOrderInsert);
        }

        $totalProduct = $this->getProductOrder();

        $this->assign('existed', $existed);

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['productId'] = $productId;
        $aryResult['totalProduct'] = $totalProduct;
        $aryResult['strContent'] = $this->getViewTemplate('home', 'product_check_exist_order');
//        $aryResult['myShopCat'] = $this->getViewTemplate('home', 'product_shop_content');
        echo json_encode($aryResult);
    }

    public function changeOrderItem() {
        $aryParam = $this->getAllPostParams();

        $orderId = $aryParam['orderId'];

        $numOfItem = $aryParam['item'];

        $price = $aryParam['price'];

        $aryOrderUpdate = array();

        $aryOrderUpdate['product_order_total_product'] = $numOfItem;

        $aryOrderUpdate['product_order_total_price'] = $numOfItem * $price;

        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'product_order_id',
                'math' => '=',
                'value' => $orderId
            )
        );

        $inOk = $this->_objModule->updateTotalItem($aryOrderUpdate, $aryConfig);

        $intOk = $this->getProductOrder();

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['leftOrderContent'] = $this->getViewTemplate('home', 'product_shop_content');
        $aryResult['listOrder'] = $this->getViewTemplate('home', 'product_list_order');
        echo json_encode($aryResult);
    }

    public function saveOrderInfo() {

        $intOk = 1;

        $aryParam = $this->getAllPostParams();

        $aryError = $this->validateOrder($aryParam);

        if (count($aryError) > 0) {
            $intOk = -2;
        }

        if ($intOk == 1) {

            $cookieShopCat = $this->getCookieData('globe_shopcat');

            $aryMethodDelivery = $this->getConfig('method_delivery');

            $aryMethodPayment = $this->getConfig('method_payment');

            $this->assign('aryMethodDelivery', $aryMethodDelivery);

            $this->assign('aryMethodPayment', $aryMethodPayment);

            $aryOrderDetail = array();
            $aryOrderDetail['order_detail_cookie_id'] = $cookieShopCat;
            $aryOrderDetail['order_detail_full_name'] = $aryParam['order_full_name'];
            $aryOrderDetail['order_detail_address'] = $aryParam['order_address'];
            $aryOrderDetail['order_detail_phone_number'] = $aryParam['order_phone_number'];
            $aryOrderDetail['order_detail_email'] = $aryParam['order_email'];
            $aryOrderDetail['order_detail_address_delivery'] = $aryParam['order_address_delivery'];
            $aryOrderDetail['order_detail_method_delivery'] = $aryParam['method_delivery'];
            $aryOrderDetail['order_detail_delivery_name'] = $aryMethodDelivery[$aryParam['method_delivery']];
            $aryOrderDetail['order_detail_method_payment'] = $aryParam['method_payment'];
            $aryOrderDetail['order_detail_payment_name'] = $aryMethodPayment[$aryParam['method_payment']];
            $aryOrderDetail['order_detail_company_name'] = $aryParam['order_company_name'];
            $aryOrderDetail['order_detail_company_address'] = $aryParam['order_company_address'];
            $aryOrderDetail['order_detail_company_tax_code'] = $aryParam['order_company_tax_code'];
            $aryOrderDetail['order_detail_created_date'] = date('Y-m-d H:i:s');

            $this->_objModule->checkExistOrderDetail($cookieShopCat, $aryData);

            if (isset($aryData[0])) {

                $aryConfig = array(
                    array(
                        'keyword' => 'where',
                        'field' => 'order_detail_id',
                        'math' => '=',
                        'value' => $aryData[0]['order_detail_id']
                    )
                );

                $detailId = $aryData[0]['order_detail_id'];

                $intOk = $this->_objModule->updateProductOrderDetail($aryOrderDetail, $aryConfig);
            } else {

                $intOk = $this->_objModule->insertOrderDetail($aryOrderDetail, $returnOrderId);

                $detailId = $returnOrderId;
            }

            if ($intOk == 1) {

                $this->_objModule->updateOrder($detailId, $cookieShopCat);

                $this->getProductOrder();

                $this->assign('aryProductOrderDetail', $aryOrderDetail);
            }
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['aryError'] = $aryError;
        $aryResult['messageError'] = _ORDER_MESSAGE_ERROR;
        $aryResult['shopContent'] = $this->getViewTemplate('home', 'product_order_bill');
//        $aryResult['shopLeftContent'] = $this->getViewTemplate('home', 'product_shop_content');
        echo json_encode($aryResult);
    }

    public function validateOrder($aryParam) {
        $objValidator = new Validator();

        $aryError = array();

        $flag = $objValidator->validateEmpty($aryParam['order_full_name']);
        if ($flag == true) {
            $aryError['order_full_name_error'] = _ORDER_EMPTY_FULL_NAME;
        }
        $flag = $objValidator->validateEmpty($aryParam['order_address']);
        if ($flag == true) {
            $aryError['order_address_error'] = _ORDER_EMPTY_ADDRESS;
        }
        $flag = $objValidator->validateEmpty($aryParam['order_phone_number']);
        if ($flag == true) {
            $aryError['order_phone_number_error'] = _ORDER_EMPTY_PHONE_NUMBER;
        } else {
            $flag = $objValidator->validatePhone($aryParam['order_phone_number']);
            if ($flag == false) {
                $aryError['order_phone_number_error'] = _ORDER_ERROR_FORMAT_PHONE_NUMBER;
            }
        }
        $flag = $objValidator->validateEmpty($aryParam['order_email']);
        if ($flag == true) {
            $aryError['order_email_error'] = _ORDER_EMPTY_EMAIL;
        } else {
            $flag = $objValidator->validateMail($aryParam['order_email']);
            if ($flag == false) {
                $aryError['order_email_error'] = _ORDER_ERROR_FORMAT_MAIL;
            }
        }
        $flag = $objValidator->validateEmpty($aryParam['order_address_delivery']);
        if ($flag == true) {
            $aryError['order_address_delivery_error'] = _ORDER_EMPTY_ADDRESS_DELIVERY;
        }
        return $aryError;
    }

    public function activeOrder() {

        $cookieShopCat = $this->getCookieData('globe_shopcat');

        $intOk = $this->_objModule->activeOderDetail($cookieShopCat);

        if ($intOk == 1) {

            $this->clearCookie('globe_shopcat');

            $this->setCookieShopCat();
        }



        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['url'] = $this->getRootPage();
        $aryResult['message'] = _ORDER_ACTIVE_SUCCESS;
        echo json_encode($aryResult);
    }

    public function setCookieShopCat() {
        $this->setCookieData('globe_shopcat', md5(time()));
    }

    public function getSlider() {
        $intOk = $this->_objModule->getSlider($aryData);
        $this->assign('arySlider', $aryData);
    }

    public function tintuc() {

        $this->getSlider();

        $limit = $this->getConfig('top_news');

        $this->_objModule->getTopNews($aryTopNews, 1, $limit);

        $this->getTopNewsView();

        $this->_objModule->getNewsCategory($aryNewsCategory);

        $this->listSupportOnline();

        $aryMainCat = array();

        $arySubCat = array();

        $aryNews = array();
        $n = 0;

        foreach ($aryNewsCategory as $key => $value) {
            if ($value['news_category_level'] == 0) {
                $aryMainCat[$n]['news_category_id'] = $value['news_category_id'];
                $aryMainCat[$n]['news_category_name'] = $value['news_category_name'];
                $aryMainCat[$n]['news_category_filter'] = $value['news_category_filter'];
                $this->_objModule->getNewsByCategoryId($value['news_category_id'], 6, $aryNews[$value['news_category_id']]);
//                if ($value['news_category_product_child_cat'] != '') {
//                    $this->_objModule->getProductInNewsByCatId($value['news_category_product_child_cat'], $limitProduct, $aryProduct[$value['news_category_id']]);
//                }
                $n++;
            }
        }
        $n = 0;
        foreach ($aryNewsCategory as $key => $value) {
            if ($value['news_category_level'] == 1) {
                $arySubCat[$n]['news_category_id'] = $value['news_category_id'];
                $arySubCat[$n]['news_category_parent'] = $value['news_category_parent'];
                $arySubCat[$n]['news_category_name'] = $value['news_category_name'];
                $arySubCat[$n]['news_category_filter'] = $value['news_category_filter'];
                $n++;
            }
        }
        $this->getNewsProduct();
        $this->assign('aryNewsCategory', $aryMainCat);
        $this->assign('aryNewsSubCategory', $arySubCat);
        $this->assign('aryNewsData', $aryNews);
        $this->assign('aryFirtNews', $aryTopNews[0]);
        unset($aryTopNews[0]);
        $this->assign('aryTopNews', $aryTopNews);
//        $this->assign('aryTopTenNews', $aryTopTenNews);
//        $this->assign('aryProductCategory', $aryProductCategory);
        $strTitle = 'Tin Tức';
        $this->assign('title', $strTitle);
        $this->assign('keywords', str_replace(" - ", ",", $strTitle));
        $this->setViewTemplate('news', 'news_index');
    }

    public function getNewsProduct() {
        $listProductCategory = '10';
        $limitProduct = $this->getConfig('limit_product_in_news');
        $this->_objModule->getTopProduct(1, $limitProduct, $listProductCategory, $aryProduct);
        $this->assign('aryProduct', $aryProduct);
    }

    public function tin() {

//        $this->buildMenu();
        $this->getNewsProduct();

        $newsCategoryId = $this->getParamOnUrlByKey(1);

        $aryNewsParentCateogry = $this->builNewsParentCategory($newsCategoryId);

//        $this->_objModule->getProductCategoryInNews($newsCategoryId, $aryData);
//        if (isset($aryData[0]['news_category_product_child_cat'])) {
//
//            $listProductCategory = $aryData[0]['news_category_product_child_cat'];
//        } else {
//
//            $listProductCategory = 0;
//        }
//        $this->_objModule->getTopProduct(3, 10, $listProductCategory, $aryTopProduct);
//        $this->_objModule->getTopProduct(1, 10, $listProductCategory, $aryNewsProduct);

        $limit = $this->getConfig('limit_news_by_news_cat');

        $this->_objModule->getNewByListNewsCategory($newsCategoryId, $limit, $aryNews);

        $this->assign('aryNewsFirst', $aryNews[0]);

        unset($aryNews[0]);

        $this->assign('aryNews', $aryNews);

//        $this->assign('aryTopProduct', $aryTopProduct);
//        $this->assign('aryNewsProduct', $aryNewsProduct);
//        $this->_objModule->getProductCategory($aryProductCategory);
        $this->getTopNewsView();

//        $this->assign('aryProductCategory', $aryProductCategory);

        $this->assign('aryNewsParentCateogry', $aryNewsParentCateogry);

        foreach ($aryNewsParentCateogry as $key => $value) {
            $strTitle.= ' ' . $value['news_category_name'];
        }

        $this->assign('title', $strTitle . ' ' . $this->getConfig('title'));

        $this->setViewTemplate('news', 'news_by_category');
    }

    public function builNewsParentCategory($newsCategoryId) {

        $aryNewsParentCat = $this->_objModule->getNewsCategoryParentPath($newsCategoryId);

        array_push($aryNewsParentCat, $newsCategoryId);

        $strNewsCategory = @implode(",", $aryNewsParentCat);

        $this->_objModule->getNewsCategoryByListId($strNewsCategory, $aryCategory);

        return $aryCategory;
    }

    public function chitiet() {

//        $this->buildMenu();
        $this->getNewsProduct();

        $newsId = $this->getParamOnUrlByKey(1);

        $this->_objModule->updateNewsViews($newsId);

        $this->_objModule->getNewsDetail($newsId, $aryNewsData);

        $aryNews['news_title'] = $this->convertUnicode($aryNewsData[0]['news_title']);
        $aryNews['news_content'] = $this->convertUnicode($aryNewsData[0]['news_content']);
        $aryNews['news_updated_date'] = $aryNewsData[0]['news_updated_date'];
        $aryNews['news_new_sub_category_id'] = $aryNewsData[0]['news_new_sub_category_id'];

        $aryKeywordReplace = $this->getConfig('keyword_replace');

        foreach ($aryKeywordReplace as $key => $keyword) {

            $aryKeywords = explode(",", $keyword['name']);

            foreach ($aryKeywords as $key2 => $value) {

                $aryKey[] = "/$value/";
                $aryLink[] = '<a href=' . $keyword['replace'] . '>' . $value . '</a>';
            }
        }

        $aryNews['news_content'] = preg_replace($aryKey, $aryLink, $aryNews['news_content']);

        $newsSubCategoryId = $aryNewsData[0]['news_new_sub_category_id'];

        $aryNewsParentCateogry = $this->builNewsParentCategory($newsSubCategoryId);

//        $this->_objModule->getProCatByNewCat($newsSubCategoryId, $aryProCat);
//        $listProductCategory = $aryProCat[0]['news_category_product_child_cat'];
//        $this->_objModule->getTopProduct(1, 10, $listProductCategory, $aryNewProduct);
//        $this->_objModule->getTopProduct(2, 10, $listProductCategory, $aryPromProduct);

        $this->_objModule->getSameNewByNewsCategory($newsSubCategoryId, 10, $aryNewsSameData, $newsId);

        $this->getTopNewsView();

        $this->assign('arySameNews', $aryNewsSameData);

        $this->assign('aryNews', $aryNews);

//        $this->assign('aryNewProduct', $aryNewProduct);
//        $this->assign('aryPromProduct', $aryPromProduct);

        $this->assign('aryNewsParentCateogry', $aryNewsParentCateogry);

        $this->assign('title', $aryNewsData[0]['news_title']);

        $this->assign('keywords', $aryNewsData[0]['news_title']);

        $this->setViewTemplate('news', 'news_detail');
    }

    public function getTopNewsView() {
        $this->_objModule->getNewsTopViews(10, $aryNewsTopViews);

        $this->assign('aryTopViews', $aryNewsTopViews);
    }

    public function searchProduct() {

        $aryParam = $this->getAllPostParams();

        $order = $this->getParam('order');

        $page = $this->getParam('page');

        $aryResult = array();

        $aryConditions = array();

        switch ($order) {
            case "price_up":
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'ASC';
                break;
            case "price_down":
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'DESC';
                break;
            case "name_up":
                $aryConditions['field'] = 'product_title';
                $aryConditions['order'] = 'ASC';
                break;
            case "name_down":
                $aryConditions['field'] = 'product_title';
                $aryConditions['order'] = 'DESC';
                break;
        }

        $aryConditions['product_keyword'] = $this->encodingUnicode(strip_tags($aryParam['product_keyword']));

        $aryConditions['product_maker_id'] = $aryParam['product_maker'];

        $categoryId = $aryParam['product_category_id'];

        $this->_objModule->getSubCatByCatId($categoryId, $aryCategory);

        foreach ($aryCategory as $key => $value) {
            $arySubCategoryId[] = $value['category_id'];
        }

        if (count($arySubCategoryId) > 0) {
            $listCategoryId = @implode(",", $arySubCategoryId);
        } else {
            $listCategoryId = $categoryId;
        }

        $aryConditions['product_category_id'] = $listCategoryId;

        if ($aryParam['product_price_from'] == '' || !is_numeric($aryParam['product_price_from'])) {

            $aryConditions['product_price_from'] = 0;
        } else if ($aryParam['product_price_from'] != '' && is_numeric($aryParam['product_price_from'])) {

            $aryConditions['product_price_from'] = $aryParam['product_price_from'];
        }

        if ($aryParam['product_price_to'] == '' || !is_numeric($aryParam['product_price_to'])) {

            $aryConditions['product_price_to'] = 0;
        } else if ($aryParam['product_price_to'] != '' && is_numeric($aryParam['product_price_to'])) {

            $aryConditions['product_price_to'] = $aryParam['product_price_to'];
        }

        $aryConditions['current_page'] = $page;

        $aryConditions['record_per_page'] = $this->getConfig('product_per_page');

//        print_r($aryConditions);

        $intOk = $this->_objModule->searchProductData($aryConditions, $aryProduct);

        $this->assign('aryProduct', $aryProduct['data']);

        $this->setActionJSPaging("MyController.searchProduct('$order',");

        $strPaging = $this->AjaxPagination($aryProduct['paging']);

        $this->assign('strPaging', $strPaging);

        $this->assign('order', $order);

        $this->assign('page', $page);

        $aryResult['intOk'] = $intOk;

        $aryResult['content'] = $this->getViewTemplate('home', 'product_search_result');

        echo json_encode($aryResult);
    }

    public function timkiem() {

//        $this->getSessionCustomer();
//        $this->buildMenu();
        $this->listSupportOnline();

        $keyword = $this->getParam('keyword');

        $page = $this->getParam('page');

        $type = $this->getParam('type');

        $catId = $this->getParam('catId');

        $aryConditions = array();

        $aryConditions['keyword'] = $this->encodingUnicode(trim($keyword));

        $aryConditions['type'] = $type;

        if (isset($page) == false) {
            $page = 1;
        }

        $aryConditions['current_page'] = $page;

        $aryConditions['record_per_page'] = $this->getConfig('product_per_page');

        $aryConditions['product_category_id'] = $catId;

        $aryCategory = array();

        $aryProductSearch = array();

        $aryNewsResult = array();

        if (strlen($keyword) > 0) {

            $this->_objModule->searchCategoryInProduct($aryConditions, $aryCategoryProduct);

            foreach ($aryCategoryProduct as $key => $value) {
                $aryCategory[$value['product_category_id']]['product_category_name'] = $value['product_category_name'];
                $aryCategory[$value['product_category_id']]['product_category_id'] = $value['product_category_id'];
                $aryCategory[$value['product_category_id']]['product_category_total']++;
            }

            $this->_objModule->countTotalNews($aryConditions, $aryNewsResult);

            $countTotalNews = count($aryNewsResult);

            $aryPaging = array();

            $arySearchNews = array();

            if ($type == 'product' || $type == '') {

                $this->_objModule->searchAllProduct($aryConditions, $aryProductSearch);

                $aryPaging = $aryProductSearch['paging'];
            } else if ($type == 'news') {

                $this->_objModule->searchAllNews($aryConditions, $arySearchNews);

                $aryPaging = $arySearchNews['paging'];
            }
        }

        $url = $_SERVER['REQUEST_URI'];

        $url = preg_replace('/\&page=([0-9]+)/', '', $url);

        $url = preg_replace('/\.html/', '', $url);

        $link = $url . '&page=';

        $strPaging = $this->pagination($link, $aryPaging);

        $this->assign('type', $type);

        $this->assign('catId', $catId);

        $this->assign('keyword', $keyword);

        $this->assign('strPaging', $strPaging);

        $this->assign('countTotalNews', $countTotalNews);

        $this->assign('aryProductCategory', $aryCategory);

        $this->assign('aryProductSearch', $aryProductSearch['data']);

        $this->assign('arySearchNews', $arySearchNews['data']);

        $this->assign('title', 'Kết quả tìm kiếm ' . $keyword);

        $this->setViewTemplate('home', 'home_search_result');
    }

    public function productInfo() {

        $this->buildMenu();

        $this->listSupportOnline();

        $productType = $this->getParamOnUrlByKey(1);

        switch ($productType) {
            case 1:
                $productTitle = "Sản phẩm mới";
                break;
            case 2:
                $productTitle = "Sản phẩm khuyến mại";
                break;
            case 3:
                $productTitle = "Sản phẩm bán chạy";
                break;
        }
        $listType = $this->getCookieData('listType');
        if ($listType == '') {
            $listType = 1;
        }

        $cookieOrder = $this->getCookieData('order');

        $this->assign('cookieOrder', $cookieOrder);

        $aryConditions = array();

        if ($cookieOrder == '') {
            $aryConditions['field'] = 'product_price_vnd';
            $aryConditions['order'] = 'DESC';
        }
        switch ($cookieOrder) {
            case "price_up":
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'ASC';
                break;
            case "price_down":
                $aryConditions['field'] = 'product_price_vnd';
                $aryConditions['order'] = 'DESC';
                break;
            case "name_up":
                $aryConditions['field'] = 'product_title';
                $aryConditions['order'] = 'ASC';
                break;
            case "name_down":
                $aryConditions['field'] = 'product_title';
                $aryConditions['order'] = 'DESC';
                break;
        }

        $categoryId = $this->getParamOnUrlByKey(2);

        $page = $this->getParam('page');

        if (isset($categoryId) && is_numeric($categoryId)) {

            $aryCategoryId = $this->_objModule->getCategoryChildPath($categoryId);

            array_push($aryCategoryId, $categoryId);

            $strCategory = @implode(",", $aryCategoryId);

            $aryCategoryParent = $this->buildParentList($categoryId);

            $this->assign('categoryParent', $aryCategoryParent);

            if (is_array($aryCategoryParent)) {

                foreach ($aryCategoryParent as $key => $value) {

                    $strTitle.= $value['category_name'] . ' - ';
                }
            }
        }

        $aryConditions['product_category_id'] = $strCategory;

        $aryConditions['product_type_id'] = $productType;

        $aryConditions['record_per_page'] = $this->getConfig('limit_product_info');

        $aryConditions['current_page'] = $page;

        $this->_objModule->getProductInfoByType($aryConditions, $aryProuctInfo);

        $this->assign('aryProduct', $aryProuctInfo['data']);

        $this->assign('listType', $listType);

        $strTitle.=$productTitle;

        $this->assign('productTitle', $productTitle);

        $url = $_SERVER['REQUEST_URI'];

        $url = preg_replace('/\?page=([0-9]+)/', '', $url);

        $url = preg_replace('/\.html/', '', $url);

        $link = $url . '?page=';

        $strPaging = $this->pagination($link, $aryProuctInfo['paging']);

        $this->assign('strPaging', $strPaging);

        $this->assign('title', $strTitle);

        $this->assign('product_type', $productType);

        $this->setViewTemplate('home', 'product_list_product_info');
    }

    public function deleteAllOrder() {
        $cookieShopCat = $this->getCookieData('globe_shopcat');
        $aryConditions = array();
        $aryConditions['product_order_cookie_id'] = $cookieShopCat;
        $intOk = $this->_objModule->deleteAllShopCat($aryConditions);
        $aryResult = array();
        $aryResult['intOk'] = $intOk;
        $aryResult['shopContent'] = $this->getViewTemplate('home', 'product_shop_content');
        $aryResult['listOrder'] = $this->getViewTemplate('home', 'product_list_order');
        echo json_encode($aryResult);
    }

    public function deleteOrderById() {

        $orderId = $this->getPostParam('orderId');

        $aryDelete = array();

        $aryDelete['product_order_del_flag'] = 1;

        $aryConfig = array(
            array(
                'keyword' => 'where',
                'field' => 'product_order_id',
                'math' => '=',
                'value' => $orderId
            )
        );

        $intOk = $this->_objModule->deleteOrderById($aryDelete, $aryConfig);

        if ($intOk == 1) {

            $this->getProductOrder();
        }

        $aryResult = array();
        $aryResult['intOk'] = $intOk;
//        $aryResult['shopContent'] = $this->getViewTemplate('home', 'product_shop_content');
        $aryResult['listOrder'] = $this->getViewTemplate('home', 'product_list_order');
        echo json_encode($aryResult);
    }

    //hàm để update lại DB fix lỗi tìm kiếm với Đ
    public function editData() {
        $sql = "SELECT product_id,
                        product_title FROM mc_product";
        $aryResultData = array();
        $intOk = $this->_objModule->getArray($sql, $aryResultData);

        if ($intOk == 1) {

            foreach ($aryResultData as $key => $value) {

                $aryConfig = array(
                    array(
                        'keyword' => 'where',
                        'field' => 'product_id',
                        'math' => '=',
                        'value' => $value['product_id']
                    )
                );

                $aryUpdate = array();
                $aryUpdate['product_title_search'] = $this->encodingUnicode($value['product_title']);
                $intOk = $this->_objModule->update('mc_product', $aryUpdate, $aryConfig);
            }
        }
        echo $intOk;
    }

    //hàm để thực hiện edit lại DB lọc keyword theo danh mục
    public function editCategoryKeyword() {
        $sql = "SELECT category_id,
                        category_name
                FROM mc_product_category ";
        $this->_objModule->getArray($sql, $aryResultData);
        foreach ($aryResultData as $key => $value) {
            $aryCategory[$key]['category_id'] = $value['category_id'];
            $category_keyword = str_replace(" -", "", $value['category_name']);
            $category_keyword = str_replace(" &", "", $category_keyword);
            $category_keyword = trim($category_keyword);
            $aryCategory[$key]['category_keyword'] = str_replace(" ", ",", $category_keyword);
        }

//        print_r($aryCategory);

        foreach ($aryCategory as $key => $value) {
            $aryConfig = array(
                array(
                    'keyword' => 'where',
                    'field' => 'category_id',
                    'math' => '=',
                    'value' => $value['category_id']
                )
            );

            $aryCategoryUpdate = array();
            $aryCategoryUpdate['category_keyword'] = $value['category_keyword'];

            $intOk = $this->_objModule->update('mc_product_category', $aryCategoryUpdate, $aryConfig);
        }

        echo $intOk;

        $this->setViewTemplate('news', 'news_detail');
    }

    //ham edit lại status show news category 1:show; 0:not show
    public function editShowNewCategory() {
        $sql = "UPDATE mc_news_category set news_category_is_show = 1";
        $intOk = $this->_objModule->Excute($sql);
        echo $intOk;
    }

    public function setOrderProduct() {
        $orderType = $this->getPostParam('orderType');
        $this->setCookieData('order', $orderType);
    }

    public function getListProduct() {
        $listType = $this->getParam('listType');
        $value = $this->getParam('value');
        switch ($listType) {
            case "list":
                $this->setCookieData('listType', $value);
                break;
            case "order":
                $this->setCookieData('mct_order', $value);
                break;
        }
    }

    public function submitLink() {
        $aryParam = $this->getAllPostParams();
        $strError = '';
        $intOk = 0;
        $aryCustomer = $this->getSession('customer');
        $count = 0;
        $countLink = count($aryParam['item_link']);
        $aryResult = array();
        if ($aryCustomer['customer_id'] == '') {
            $aryResult['intOk'] = $intOk;
            $aryResult['strError'] = _CUSTOMER_NOT_LOGIN;
            echo json_encode($aryResult);
            return;
        }
        if ($aryCustomer['customer_id'] != '') {
            foreach ($aryParam['item_link'] as $key => $value) {
                if ($value['item_link'] == '') {
                    $count++;
                } else {
                    $aryCustomerLink = array();
                    $aryCustomerLink['mct_customer_link_link'] = $value;
                    $aryCustomerLink['mct_customer_link_customer_id'] = $aryCustomer['customer_id'];
                    $aryCustomerLink['mct_customer_link_product_id'] = $aryParam['product_id'];
                    $aryCustomerLink['mct_customer_link_send_date'] = date("Y-m-d H:i:s");
                    $intOk = $this->_objModule->saveCustomerLink($aryCustomerLink);
                }
            }
        }
        if ($count == $countLink) {
            $strError = _CUSTOMER_EMPTY_LINK;
        }
        $aryResult['intOk'] = $intOk;
        $aryResult['strError'] = $strError;
        $aryResult['messageSuccess'] = _CUSTOMER_SEND_LINK_SUCCESS;
        echo json_encode($aryResult);
    }

    public function getSessionCustomer() {
        $aryCustomerInfo = $this->getSession('customer');
        $this->assign('sessionCustomer', $aryCustomerInfo);
    }

    public function logout() {
        $this->clearSession('customer');
        $this->redirectURL($this->_rootPage . "");
        $this->setViewTemplate('maccathue_new', 'logout');
    }

    public function printOrder() {
        $this->assign('title', 'In đơn hàng');
        $this->setViewTemplate('home', 'print_order_detail');
    }

    public function compare() {
        $this->buildMenu();
        $this->getProductOrder();
        $list = $this->getParam('list');
        $aryList = explode(",", $list);
        $aryListProductId = array();
        $count = 0;
        foreach ($aryList as $key => $value) {
            if ($value != '') {
                $aryListProductId[] = $value;
                $count++;
            }
            if ($count == 3) {
                break;
            }
        }

        $cookieShopCat = $this->getCookieData('globe_shopcat');

        $inOk = $this->_objModule->getProductIdInOrder($cookieShopCat, $aryProductOrder);

        $aryOrderProductId = array();

        foreach ($aryProductOrder as $key => $value) {

            $aryOrderProductId[] = $value['product_order_product_id'];
        }

        $this->assign('aryOrderProductId', $aryOrderProductId);

        $listProductId = @implode(",", $aryListProductId);

        $intOk = $this->_objModule->getProductByListId($listProductId, $aryProduct);

        $this->assign('aryProduct', $aryProduct);

        $this->assign('title', 'So sánh sản phẩm.');

        $this->setViewTemplate('home', 'product_compare');
    }

    public function buildNews() {
        $this->_objModule->getNewsCategory($aryCategory);
        foreach ($aryCategory as $key => $value) {
            if ($value['news_category_level'] == 0) {
                $aryRootNewsCategory[$value['news_category_id']]['news_category_id'] = $value['news_category_id'];
                $aryRootNewsCategory[$value['news_category_id']]['news_category_name'] = $value['news_category_name'];
                $aryRootNewsCategory[$value['news_category_id']]['news_category_filter'] = $value['news_category_filter'];
            }
        }

        $this->assign('aryRootNewsCategory', $aryRootNewsCategory);
        $limit = $this->getConfig('news_limit');
        $intOk = $this->_objModule->getNewsLimit($limit, $aryNews);
        $this->assign('aryNews', $aryNews);
    }

    public function lienhe() {
        $this->listSupportOnline();
        $this->buildMenu();
        $this->assign('title', 'Liên hệ');
        $this->setViewTemplate('home', 'lienhe');
    }

    public function customerContact() {
        $aryParam = $this->getAllPostParams();
        $aryCustomer['customer_contact_title'] = $aryParam['customer_contact_title'];
        $aryCustomer['customer_contact_full_name'] = $aryParam['customer_contact_full_name'];
        $aryCustomer['customer_contact_email'] = $aryParam['customer_contact_email'];
        $aryCustomer['customer_contact_mobile'] = $aryParam['customer_contact_mobile'];
        $aryCustomer['customer_contact_address'] = $aryParam['customer_contact_address'];
        $aryCustomer['customer_contact_send_date'] = date('Y-m-d H:i:s');
        $aryCustomer['customer_contact_content'] = $aryParam['customer_contact_content'];

        $aryError = array();
        $objValidator = new Validator();
        $flag = $objValidator->validateEmpty($aryParam['customer_contact_title']);
        if ($flag == true) {
            $aryError['customer_contact_title_error'] = 'Bạn chưa nhập tiêu tề liên hệ.';
        }

        $flag = $objValidator->validateEmpty($aryParam['customer_contact_email']);
        if ($flag == true) {
            $aryError['customer_contact_email_error'] = 'Bạn chưa nhập địa chỉ Email.';
        } else {
            $flag = $objValidator->validateMail($aryParam['customer_contact_email']);
            if ($flag == false) {
                $aryError['customer_contact_email_error'] = 'Địa chỉ Email không chính xác.';
            }
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_contact_mobile']);
        if ($flag == true) {
            $aryError['customer_contact_mobile_error'] = 'Bạn chưa nhập số điện thoại di động.';
        } else {
            $flag = $objValidator->validatePhone($aryParam['customer_contact_mobile']);
            if ($flag == false) {
                $aryError['customer_contact_mobile_error'] = 'Số điện thoại không chính xác.';
            }
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_contact_address']);
        if ($flag == true) {
            $aryError['customer_contact_address_error'] = 'Bạn chưa nhập địa chỉ.';
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_contact_content']);
        if ($flag == true) {
            $aryError['customer_contact_content_error'] = 'Bạn chưa nhập nội dung.';
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_contact_full_name']);
        if ($flag == true) {
            $aryError['customer_contact_full_name_error'] = 'Bạn chưa nhập họ tên.';
        }

        $captcha = $this->getSession('captcha');
        if (strtolower($aryParam['captcha_code']) != $captcha) {
            $aryError['captcha_code_error'] = _CUSTOMER_ERROR_CAPTCHA;
        }
        $aryResult = array();
        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            $aryResult['messageError'] = _CUSTOMER_MESSAGE_ERROR;
            echo json_encode($aryResult);
            return;
        }
        $intOk = $this->_objModule->saveCustomerContact($aryCustomer);
        $aryResult['intOk'] = 1;
        $aryResult['message'] = 'Thông tin liên hệ đã được gửi.';
        echo json_encode($aryResult);
    }

    public function gioithieu() {
        $this->listSupportOnline();
        $this->assign('title', 'Giới thiệu');
        $this->setViewTemplate('home', 'gioithieu');
    }

    public function getProductImage() {
        $productId = $this->getParamOnUrlByKey(1);
        $this->_objModule->getProductImageData($aryProductImage, $productId);
        $this->assign('aryProductImage', $aryProductImage);
    }

    //start

    public function dangky() {
        $aryLearning = $this->getConfig('learning');
        $this->assign('aryLearning', $aryLearning);
        $this->setViewTemplate('home', 'vmc_dangky');
    }

    public function registerCustomer() {
        $intOk = 0;
        $this->clearSession('customer');
        $aryParam = $this->getAllPostParams();
        $aryLearning = $this->getConfig('learning');
        //print_r($aryParam);
        //$aryCustomer['customer_gender'] = $aryParam['customer_gender'];
        $aryCustomer['customer_full_name'] = $aryParam['customer_full_name'];
        $aryCustomer['customer_full_name_search'] = $this->encodingUnicode($aryParam['customer_full_name']);
        //$aryCustomer['customer_user_name'] = $aryParam['customer_user_name'];
        //$aryCustomer['customer_password'] = md5(md5($aryParam['customer_password']));
        $aryCustomer['customer_email'] = $aryParam['customer_email'];
        $aryCustomer['customer_address'] = $aryParam['customer_address'];
        //$aryCustomer['customer_home_phone'] = $aryParam['customer_home_phone'];
        $aryCustomer['customer_mobile_phone'] = $aryParam['customer_mobile_phone'];
        //$aryCustomer['customer_is_ctv'] = $aryParam['customer_is_ctv'];
        $aryCustomer['customer_yahoo'] = $aryParam['customer_yahoo'];
        $aryCustomer['customer_skype'] = $aryParam['customer_skype'];
        $aryCustomer['customer_learning_id'] = $aryParam['customer_learning_id'];
        $aryCustomer['customer_learning_name'] = $aryLearning[$aryParam['customer_learning_id']];
        $aryCustomer['customer_join_date'] = date("Y-m-d H:i:s");


//        print_r($aryCustomer);
//        return;

        $aryError = array();
        $objValidator = new Validator();
        $flag = $objValidator->validateEmpty($aryParam['customer_full_name']);
        if ($flag == true) {
            $aryError['customer_full_name_error'] = _CUSTOMER_EMPTY_FULL_NAME;
        }
//        $flag = $objValidator->validateEmpty($aryParam['customer_user_name']);
//        if ($flag == true) {
//            $aryError['customer_user_name_error'] = _CUSTOMER_EMPTY_USER_NAME;
//        }
//        $username = $aryParam['customer_user_name'];
//        $intOk = $this->_objModule->getCustomerUsername($username, $aryCustumerUserName);
//        if (count($aryCustumerUserName) > 0) {
//            $aryError['customer_user_name_error'] = _CUSTOMER_USER_NAME_ERROR;
//        }
//        $flag = $objValidator->validateEmpty($aryParam['customer_password']);
//        if ($flag == true) {
//            $aryError['customer_password_error'] = _CUSTOMER_EMPTY_PASSWORD;
//        }
//        $flag = $objValidator->validateEmpty($aryParam['repassword']);
//        if ($flag == true) {
//            $aryError['repassword_error'] = _CUSTOMER_EMPTY_RE_PASSWORD;
//        }
//        if ($aryParam['customer_password'] != $aryParam['repassword']) {
//            $aryError['repassword_error'] = _CUSTOMER_PASSWORD_ERROR;
//        }
        $checkEmail = $aryParam['customer_email'];

        $flag = $objValidator->validateEmpty($aryParam['customer_email']);
        if ($flag == true) {
            $aryError['customer_email_error'] = _CUSTOMER_EMPTY_EMAIL;
        } else {
            $flag = $objValidator->validateMail($aryParam['customer_email']);
            if ($flag == false) {
                $aryError['customer_email_error'] = _CUSTOMER_ERROR_EMAIL;
            } else {
                $intOk = $this->_objModule->getCustomerEmail($checkEmail, $aryCustumerEmail);
                if (count($aryCustumerEmail) > 0) {
                    $aryError['customer_email_error'] = _CUSTOMER_EMAIL_ERROR;
                }
            }
        }
//        $flag = $objValidator->validateEmpty($aryParam['zone_id']);
//        if ($flag == true) {
//            $aryError['zone_id_error'] = _CUSTOMER_EMPTY_PROVINCE;
//        }
        $flag = $objValidator->validateEmpty($aryParam['customer_mobile_phone']);
        if ($flag == false) {
            $flag = $objValidator->validatePhone($aryParam['customer_mobile_phone']);
            if ($flag == false) {
                $aryError['customer_mobile_phone_error'] = _CUSTOMER_ERROR_FORMAT_PHONE;
            }
        } else {
            $aryError['customer_mobile_phone_error'] = _CUSTOMER_EMPTY_MOBILE_PHONE;
        }
//        $flag = $objValidator->validateEmpty($aryParam['customer_home_phone']);
//        if ($flag == false) {
//            $flag = $objValidator->validatePhone($aryParam['customer_home_phone']);
//            if ($flag == false) {
//                $aryError['customer_home_phone_error'] = _CUSTOMER_ERROR_FORMAT_PHONE;
//            }
//        }
        $flag = $objValidator->validateEmpty($aryParam['customer_address']);
        if ($flag == true) {
            $aryError['customer_address_error'] = _CUSTOMER_EMPTY_ADRESS;
        }
        //validate birthday
//        $flag = $objValidator->validateEmpty($aryParam['day']);
//        if ($flag == true) {
//            $aryError['customer_birthday_error'] = _CUSTOMER_EMPTY_DAY;
//        }
//        $flag = $objValidator->validateEmpty($aryParam['month']);
//        if ($flag == true) {
//            $aryError['customer_birthday_error'] = _CUSTOMER_EMPTY_MONTH;
//        }
//        $flag = $objValidator->validateEmpty($aryParam['year']);
//        if ($flag == true) {
//            $aryError['customer_birthday_error'] = _CUSTOMER_EMPTY_YEAR;
//        }
//        $flag = $objValidator->validateEmpty($aryParam['customer_bank_number']);
//        if ($flag == false) {
//            $flag = $objValidator->validateNumber($aryParam['customer_bank_number']);
//            if ($flag == false) {
//                $aryError['customer_bank_number_error'] = _CUSTOMER_ERROR_BANK_NUMBER;
//            }
//        }

        $flag = $objValidator->validateEmpty($aryParam['customer_yahoo']);
        if ($flag == true) {
            $aryError['customer_yahoo_error'] = _CUSTOMER_EMPTY_YAHOO;
        }
        $flag = $objValidator->validateEmpty($aryParam['customer_learning_id']);
        if($flag == true){
            $aryError['customer_learning_id_error'] = _CUSTOMER_EMPTY_CLASS;
        }

        $captcha = $this->getSession('captcha');

        $flag = $objValidator->validateEmpty($aryParam['verify_image']);
        if ($flag == true) {
            $aryError['captcha_error'] = _CUSTOMER_EMPTY_CAPTCHA;
        } else {
            if (strtolower($aryParam['verify_image']) != $captcha) {
                $aryError['captcha_error'] = _CUSTOMER_ERROR_CAPTCHA;
            }
        }

//        print_r($aryError);
//        return;

        $aryResult = array();
        if (count($aryError) > 0) {
            $aryResult['intOk'] = -2;
            $aryResult['aryError'] = $aryError;
            $aryResult['messageError'] = _CUSTOMER_MESSAGE_ERROR;
            echo json_encode($aryResult);
            return;
        }
        $intOk = $this->_objModule->saveCustomerData($aryCustomer);
        $aryResult['intOk'] = $intOk;
        $aryResult['message'] = _CUSTOMER_REGISTER_SUCCESS;
        echo json_encode($aryResult);
    }

}

?>
